import React from 'react';
import {Checkbox} from 'antd';
const CheckboxGroup = Checkbox.Group;
import {WeaSearchGroup, WeaFormItem, WeaCheckbox, WeaSelect, WeaTextarea, WeaInput, WeaError} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import WeaColorInput from '../../../../../../../pc4public/portal/wea-color-input/';
import EType from './base/EType';
import ETitle from './base/ETitle';
import EShowNum from './base/EShowNum';
import ELinkMode from './base/ELinkMode';
//import EField from './base/EField';
import EField_New from './base/EField_New'

// CoreMail邮件
export default class Content_CoreMail extends React.Component {
    state = {
        eShowUnreadList: this.props.eShowUnreadList,
        eCoreMailPerpage: this.props.eCoreMailPerpage,
        eShowPromptInformation: this.props.eShowPromptInformation,
        eSingleSignOn: this.props.eSingleSignOn || '',
        eHintText: this.props.eHintText,
        eUnreadMailQuantityColor: this.props.eUnreadMailQuantityColor,
        eSingleSignOnLinkColor: this.props.eSingleSignOnLinkColor,
        eExplain: this.props.eExplain,
        eCoreMailLinkMode: this.props.eCoreMailLinkMode,   // 链接方式
        eFieldNewDataSource: this.props.eFieldNewDataSource,
        eFieldNewUsedKeys: this.props.eFieldNewUsedKeys,
        eFieldNewVisible: false,
    };

    render() {
        const {eShowUnreadList, eCoreMailPerpage, eShowPromptInformation, eSingleSignOn, eHintText,
          eUnreadMailQuantityColor, eSingleSignOnLinkColor, eCoreMailTitle, eCoreMailUser, eCoreMailTime, eCoreMailLinkMode,
            eFieldNewDataSource, eFieldNewUsedKeys, eFieldNewVisible} = this.state;

        let EShowUnreadList = (
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@aggol9`} label={getLabel(386576, '显示未读列表')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@o9yaqj`} value={eShowUnreadList} onChange={(value)=>this.setState({eShowUnreadList: value})}/>
            </WeaFormItem>
        );
        let ECoreMailPerpage =(
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@delff1`} label={getLabel(19493, '显示条数')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@qm0ry3`} value={eCoreMailPerpage} onChange={(value)=>this.setState({eCoreMailPerpage: value})} style={{width: '22%'}}/>
            </WeaFormItem>
        );
        let EShowPromptInformation = (
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@st6gnj`} label={getLabel(386577, '显示提示信息')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@58kz7u`} value={eShowPromptInformation} onChange={(value)=>this.setState({eShowPromptInformation: value})}/>
            </WeaFormItem>
        );
        let ESingleSignOn = (
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@d1gb80`} label={getLabel(126789, '单点登录')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@8i6aji`}
                    ref={el => {this.weaError = el}}
                    error={getLabel(129952, '请选择或新建CoreMail集成登录设置！')}
                    style={{width: '22%'}}>
                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@uru7d3`} value={eSingleSignOn} viewAttr={'3'} options={this.props.coreMailSysids.options} onChange={(value)=>this.setState({eSingleSignOn: value})} style={{width: '100%'}}/>
                </WeaError>
            </WeaFormItem>
        );
        let EHintText =(
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@b9ba0v`} label={getLabel(129937, '提示文字')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@xbnd2l`} value={eHintText} onChange={(value)=>this.setState({eHintText: value})} style={{width: '300px'}}/>
            </WeaFormItem>
        );
        let EUnreadMailQuantityColor =(
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@wsnn41`} label={getLabel(129938, '未读邮件数量颜色')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaColorInput ecId={`${this && this.props && this.props.ecId || ''}_WeaColorInput@f2j9wz`} color={eUnreadMailQuantityColor} onChange={(value)=>this.setState({eUnreadMailQuantityColor: value})}/>
            </WeaFormItem>
        )
        let ESingleSignOnLinkColor =(
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@l2vjtv`} label={getLabel(129939, '单点登录链接颜色')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaColorInput ecId={`${this && this.props && this.props.ecId || ''}_WeaColorInput@lbkn9u`} color={eSingleSignOnLinkColor} onChange={(value)=>this.setState({eSingleSignOnLinkColor: value})}/>
            </WeaFormItem>
        )
        let EExplain =(
            this.props.eShareLevel == '2'&&<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@o6zg2q`} label={getLabel(25734, '说明')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@akubbj`} value={"&nbsp;$NoReadCnt$ : "+getLabel(129940, '未读邮件数量')+"\n $LoginLinkStart$ : "+getLabel(129941, '单点登录链接开始')+"\n $LoginLinkEnd$ : "+getLabel(129942, '单点登录链接结束') } viewAttr={1}/>
            </WeaFormItem>
        );
        let EFieldNew = <div></div>;
        if (eFieldNewVisible) {
            const eFieldNewProps = {
                eFieldNewDataSource: _.cloneDeep(eFieldNewDataSource),
                eFieldNewUsedKeys: _.cloneDeep(eFieldNewUsedKeys),
                onOk: (data) => {
                    this.setState({
                        eFieldNewDataSource: _.cloneDeep(data.eFieldNewDataSource),
                        eFieldNewUsedKeys: _.cloneDeep(data.eFieldNewUsedKeys),
                        eFieldNewVisible: false
                    });
                },
                onCancel: () => {
                    this.setState({
                        eFieldNewVisible: false
                    });
                }
            };
            EFieldNew = <EField_New ecId={`${this && this.props && this.props.ecId || ''}_EField_New@i71vvm`} {...eFieldNewProps}/>
        }
        const eFieldNewUsedNames = [];
        for (let i = 0; i < eFieldNewUsedKeys.length; i++) {
            for (let j = 0 ; j < eFieldNewDataSource.length; j++) {
                if (eFieldNewUsedKeys[i] == eFieldNewDataSource[j].key) {
                    eFieldNewUsedNames.push(eFieldNewDataSource[j].name);
                }
            }
        }
        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@ghck2a`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true}>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@8eo9s8`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@4ybtxz`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle}  {...this.props}/> : ''}
                    {/*<EShowNum ref="eShowNum" value={this.props.eShowNum}/>*/}
                </WeaSearchGroup>
                 <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@7vbakc`} title={getLabel(386578, '未读列表')} needTigger={true} showGroup={true}>
                    {EShowUnreadList}{/*显示未读列表*/}
                    {ECoreMailPerpage}{/*显示条数*/}
                    <ELinkMode ecId={`${this && this.props && this.props.ecId || ''}_ELinkMode@w8l675`} ref="eLinkMode" options={this.props.eLinkMode.options} value={this.props.eLinkMode.selected}/>
                    {ESingleSignOn}{/*单点登录*/}
                    {/*<EField ref="eField" value={this.props.eField}/>*/}
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@h76z1s`} label={getLabel(19495, '显示字段')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                        {EFieldNew}
                        <div style={{height: '30px', lineHeight: '23px'}}>
                            <i className="icon-coms-Flow-setting portal-esetting-btn" onClick={() => this.setState({eFieldNewVisible: true})}/>
                            <span>{eFieldNewUsedNames.join('，')}</span>
                        </div>
                    </WeaFormItem>
                </WeaSearchGroup>
                 <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@zelb0q`} title={getLabel(24960, '提示信息')} needTigger={true} showGroup={true}>
                    {EShowPromptInformation}{/*显示提示信息*/}
                    {EHintText}{/*提示文字*/}
                    {EUnreadMailQuantityColor}{/*未读邮件数量颜色*/}  
                    {ESingleSignOnLinkColor}{/*单点登录链接颜色*/}
                    {EExplain}{/*说明*/}
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        if(this.state.eSingleSignOn == '') {
            this.weaError.showError();
            return false;
        }
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            //eContentShowNum: this.refs['eShowNum'].getSaveValues(),
            eContentLinkMode: this.refs['eLinkMode'].getSaveValues(),
            //eContentField: this.refs['eField'].getSaveValues(),
            eContentShowUnreadList: this.state.eShowUnreadList,
            eContentCoreMailPerpage: this.state.eCoreMailPerpage,
            eContentSingleSignOn: this.state.eSingleSignOn,
            eContentShowPromptInformation: this.state.eShowPromptInformation,
            eContentHintText: this.state.eHintText,
            eContentUnreadMailQuantityColor: this.state.eUnreadMailQuantityColor,
            eContentSingleSignOnLinkColor: this.state.eSingleSignOnLinkColor,
            eContentCoreMailLinkMode: this.state.eCoreMailLinkMode,
            eContentFieldNewUsedKeys: this.state.eFieldNewUsedKeys
        };
    }
}